#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

Ok_name=''
Fail_name=''
Judge=0
currentcpuload=`uptime | awk -F"load average:" '{print $NF}'|awk -F" " '{print $1}'|awk -F"." '{print $1}'`
if [ $currentcpuload -ge 100 ];then
    echo "cpuload is $currentcpuload"
    exit $CRITICAL
fi


for choice in besfs2new                       ###
do
        case $choice in
        besfs2)
                #hostname -s |awk '{print substr($1,1,3)}'                 ###
                #if
        ### check memory

              mem_use=`ps aux|grep besvol|grep -v grep|awk 'NR==1 {print $6}'`

              if [ $mem_use -gt 3145728 ]
              then
                        echo "gluster_besfs2 used memory: $mem_use KB, which is over used"
                        /etc/init.d/besfs2 stop
                        /etc/init.d/besfs2 start
                        exit $CRITICAL

             else
                        echo "gluster_besfs2: mem is ok"
                        #exit $OK
             fi


              TT=`uname -a |awk '{print $3,$14}'`

              if [ "$TT" != "2.6.9-89.0.16.EL.cernsmp i386" ]
              then

                touch /$choice/nms/testfs
                if [ -w /$choice/nms/testfs ]            ###
                then
                        Ok_name="${Ok_name} ${choice}"
                else
                        Judge=1
                        Fail_name="${Fail_name} ${choice}"
                fi
              fi

              ;;
        esac

done

if [ $Judge -eq 1 ]
then
        echo "gluster_besfs2: $Fail_name  wrong"
        /etc/init.d/gluster stop
        /etc/init.d/gluster start
        exit $CRITICAL
else
        echo " gluster_besfs2:$Ok_name are OK "
        exit $OK
fi
